export default {
    require(name) {
        return { required: true, message: `请输入${name}`, trigger: 'change' }
    },
    max(max) {
        return {
            min: 1,
            max: max,
            message: `最多${max}个字符`,
            trigger: 'change'
        }
    },
    regC() {
        return {
            required: true,
            pattern: /^[\u4e00-\u9fa5a-zA-Z0-9$-_()]+$/,
            message: "由大小写字母、数字、汉字 、$、_、-、(、)组成",
            trigger: 'change'
        }
    },
    regE() {
        return {
            required: true,
            pattern: /^[a-zA-Z0-9$-_()]+$/,
            message: "由大小写字母、数字、$、_ 、- 、(、)组成",
            trigger: 'change'
        }
    },
    regVersion() {
        return {
            required: true,
            pattern: /^[a-zA-Z0-9.]+$/,
            message: "由大小写字母、数字、.组成",
            trigger: 'change'
        }
    },
    initRule(obj) {
        var rule = {}
        if (obj instanceof Object) {
            for (let key in obj) {
                let itemList = obj[key].split(';')
                rule[key] = itemList.map((item) => {
                    if (item.indexOf(':') != -1) {
                        if (item.split(':')[0] == 'require') {
                            return this['require'](item.split(':')[1])
                        } else if (item.split(':')[0] == 'max') {
                            return this['max'](Number(item.split(':')[1]))
                        }
                    } else {
                        return this[item]()
                    }

                })
            }
        }
        return rule
    }
}